public class CDecimal implements Decimal {

  public static long count () { return ncount(); }

  public CDecimal (String src) { _ref = nnew(src); }

  @Override
  public void release () { ndelete(_ref); }

  @Override
  public int cmp (Decimal other) { return ncmp(_ref, ((CDecimal)other)._ref); }

  @Override
  public Decimal add (Decimal other) { return new CDecimal(nadd(_ref, ((CDecimal)other)._ref)); }

  @Override
  public Decimal sub (Decimal other) { return new CDecimal(nsub(_ref, ((CDecimal)other)._ref)); }

  @Override
  public Decimal mul (Decimal other) { return new CDecimal(nmul(_ref, ((CDecimal)other)._ref)); }

  @Override
  public Decimal div (Decimal other, RoundMode mode) { return new CDecimal(ndiv(_ref, ((CDecimal)other)._ref, mode.c)); }

  @Override
  public Decimal neg () { return new CDecimal(nneg(_ref)); }

  @Override
  public Decimal abs () { return new CDecimal(nabs(_ref)); }

  @Override
  public Decimal pow (int exp) { return new CDecimal(npow(_ref, exp)); }

  @Override
  public Meta meta () { return nmeta(_ref); }


  private CDecimal (long ref) { _ref = ref; }

  private static native long nnew (String src);
  private static native void ndelete (long ref);
  private static native int ncmp (long op1, long op2);
  private static native long nadd (long op1, long op2);
  private static native long nsub (long op1, long op2);
  private static native long nmul (long op1, long op2);
  private static native long ndiv (long op1, long op2, int mode);
  private static native long nneg (long src);
  private static native long nabs (long src);
  private static native long npow (long src, int exp);
  private static native Meta nmeta (long ref);
  private static native long ncount ();

  private long _ref;
}
